package com.class04.dao.impl;

import com.class04.dao.StudentDao;
import com.class04.domain.Student;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class StudentDaoImpl implements StudentDao {


    private JdbcTemplate jdbcTemplate;
//    注入容器我们的jdbcTemplate对象


    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public List<Student> queryAll() {
//        BeanPropertyRowMapper帮助我们自动映射列和属性值，要求列名和属性名一致！
//        不一致 就起别名
//        sql = "select * from students;";
        String sql = "select  id,name,gender,age,class as classes from  students;";
        List<Student> studentList = jdbcTemplate.query(sql,
                new BeanPropertyRowMapper<Student>(Student.class));
        System.out.println("studentDao:" + studentList);
        return studentList;
    }

}
